#ifndef UUID_F1B2055ADDBD4FC8FD2E61A4E8849AE0
#define UUID_F1B2055ADDBD4FC8FD2E61A4E8849AE0

extern "C" {
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
}

void* lua_check_object(lua_State* L, int idx, int tag, char const* extramsg);
void* lua_try_object(lua_State* L, int idx, int tag);
void lua_clear_object_tag(lua_State* L, int idx);

// Create an object with a certain userdata tag and size. Uses the environment
// of the current function as metatable. NOTE: The object should be
// initialized before any calls that may trigger GC.
void* lua_create_object(lua_State* L, int tag, int size);
void* lua_create_object_no_mt(lua_State* L, int tag, int size);

#define LUA_CHECK_FUNC(type, name, tag) \
inline type& check_##name(lua_State* L, int idx) { \
	return *static_cast<type*>(lua_check_object(L, idx, tag, #name)); \
} \
inline type* try_##name(lua_State* L, int idx) { \
	return static_cast<type*>(lua_try_object(L, idx, tag)); \
}

#endif // UUID_F1B2055ADDBD4FC8FD2E61A4E8849AE0
